<template>
  <Modal v-model="modal" title="审核未通过原因">
    <Form :label-width="50" ref="form" :model="form" :rules="rules">
      <FormItem label="原因" prop="auditRemark">
        <Input v-model="form.auditRemark" type="textarea" :rows="3" :maxlength="100"/>
      </FormItem>
    </Form>
    <div slot="footer">
      <Button class="mr" size="large" type="text" @click="closeModal">取消</Button>
      <Button type="primary" size="large" :disabled="disabled" @click="onSave">确定</Button>
    </div>
  </Modal>
</template>
<script>
export default {
  props: {
    checkQuery: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      modal: false,
      disabled: false,
      id: null,
      param: {},
      form: {
        auditRemark: ''
      },
      rules: {
        auditRemark: [
          { required: true, message: '请输入审核不通过的原因', trigger: "blur" }
        ]
      }
    }
  },
  methods: {
    updataForm(id, param) {
      this.disabled = false
      this.id = id
      this.$refs.form.resetFields()
      this.param = param
      this.openModal()
    },
    openModal() {
      this.modal = true;
    },
    closeModal() {
      this.modal = false
    },
    onSave() {
      if (this.disabled) return
      this.disabled = true
      this.$refs["form"].validate(valid => {
        if (valid) {
          let param = {
            id: this.id,
            isAudit: false,
            auditFundAmount: 0,
            auditRemark: this.form.auditRemark,
            query: {
              ...this.checkQuery
            }
          }
          this.$jsonPost(`/assets/fund_month/audit`, param).then(data => {
            this.closeModal()
            this.$Notice.success({
              title: '审核不通过的原因提交成功'
            })
            this.$emit('complete', data)
          }).catch(() => {
            this.closeModal()
            this.disabled = false
          })
        } else {
          this.disabled = false
        }
      })
    }
  }
}
</script>
